package com.abc.model;

import java.util.*;

public class Project {
	
	private String name;
	
	/** mapping 'year' to 'project year' details */
	private Map<String, ProjectYear> projectYears = new HashMap<String, ProjectYear>();
	
	public Project(String newName) {
		this.name = newName;
	}

	public boolean addProjectYear(ProjectYear projectYear) {
		return projectYears.put(projectYear.getYear(), projectYear) != null;
	}
	
	public String getName() {
		return name;
	}

	public Collection<PersonYearEffort> getEfforts(String year) {
		return projectYears.get(year).getDeveloperYearEfforts();
	}

	public Map<String, ProjectYear> getProjectYears() {
		return projectYears;
	}
	
	public Set<String> getDevNames() {
		Set<String> names = new HashSet<String>();
						
		Collection<ProjectYear> pYears = projectYears.values();
		for(ProjectYear projDetail : pYears) {
			Set<String> devNames = projDetail.getDeveloperYearEffortsByDevName().keySet();
			names.addAll(devNames);
		}
		return names;
	}

	public double getAllEffort(String devName){
		
		double all = 0;
		Set<String> years = projectYears.keySet();
		for(String year : years){
			ProjectYear py = this.projectYears.get(year);
			for(PersonYearEffort pye : py.getDeveloperEffortsByDeveloperName(devName))
			{
				all=all + pye.getAllEffortForYear();
			}
		}
		
		return all;
	}

	public String toString(){
		return getName();
	}	
	public void vvv() {
		Set<String> years = projectYears.keySet();
		for(String yy : years) {
			//TODO get
			ProjectYear ppp = projectYears.get(yy);
			String developerID = "dev-2010";
			ppp.getDeveloperEfforts(developerID);
			//for (PersonYearEffort person1: )
		}
	}
	
}
